<?php
/**
 *微信 分享
 */

namespace app\api\controller;

use app\api\model\User;
use think\Request;
use think\Loader;
class Promote extends Common
{

    public function postWxShareConfig(Request $request)
    {
        Loader::import('Wxchat.Api');

        $user_id = $this->checkLoginUser(true);

        $url = $request->post('url');
        //1 表示 商品分享， 2 表示 邀请码 分享
        $type = $request->post('type');

        if($type ==2)
        {
           $info = User::getExtendInfo($user_id);
            if($info && !empty($info['user_invite_code']))
            {
                //在 登录页面 获取 该参数名
                $url.='?invite_code='.$info['user_invite_code'];
            }

        }
        $wx_config = load_scope_config('weixin');
        //var_dump($wx_min_program_config);die;
        $wx_api = new \Api([
            'appId' => $wx_config['appid'],
            'appSecret' => $wx_config['app_secret'],
            'mchId' => $wx_config['mchid'],
            'key' => $wx_config['key']
        ]);

        to_json_encode(200,'success',$wx_api->get_jsapi_config($url));
	}
}